import React, { Fragment } from 'react';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import { Grid, LinearProgress } from '@material-ui/core';
import PropTypes from 'prop-types';
import { withFormik } from 'formik';
import * as Yup from 'yup';
export const DisplayFormikState = props => (
<div style={{ margin: '1rem 0' }}>
<pre
style={{
background: '#f6f8fa',
fontSize: '.65rem',
padding: '.5rem',
}}
>
<strong>props</strong> ={' '}
{JSON.stringify(props, null, 2)}
</pre>
</div>
);
const formikEnhancer = withFormik({
enableReinitialize: true,
validationSchema: Yup.object().shape({
prepNote: Yup.string().required('Note is required'),
}),
mapPropsToValues: props => ({
prepNote: props.prepNote ? props.prepNote : '',
submitForm: props.submitForm,
}),
handleSubmit: (values, { setSubmitting }) => {
const {
submitForm, ...rest
} = values;
submitForm(rest).then(() => {
setSubmitting(false);
}, () => {
setSubmitting(false);
});
},
displayName: 'MyForm',
});
const Form = props => {
const {
values: {
prepNote,
},
errors,
touched,
handleChange,
isValid,
setFieldTouched,
isSubmitting,
editDisabled,
} = props;
const change = (name, e) => {
e.persist();
handleChange(e);
setFieldTouched(name, true, false);
};